const program = require('commander')

const {
  createProjectAction,
  addComponentAction,
  addPageAndRouteAction,
  addStoreAction
} = require('./action')

const createCommands = () => {
  program
    .command('create <project> [others...]')
    .description('clone respository into a folder')
    .action(createProjectAction)

  program
    .command('addcpn <component>')
    .description('add vue component, 例如: why addcpn HelloWorld [-d src/components]')
    .action((name) => {
      addComponentAction(name, program.opts().dest || 'src/components')
    })

  program 
    .command('addpage <page>')
    .description('add vue page and router config, 例如: why addpage Home [-d src/pages]')
    .action((name) => {
      addPageAndRouteAction(name, program.opts().dest || 'src/pages')
    })

  program
    .command('addstore <store>')
    .description('add vue store, 例如: why addstore helloStore [-d src/store]')
    .action((store) => {
      addStoreAction(store, program.opts().dest || `src/store/modules/${store.toLowerCase()}`)
    })
}

module.exports = createCommands